package com.muyu.danmo.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoCity;
import com.muyu.danmo.domain.DanmoCounty;
import com.muyu.danmo.domain.DanmoProvince;
import com.muyu.danmo.req.DanmoCountyReq;
import com.muyu.danmo.req.DanmoProvinceReq;
import com.muyu.danmo.service.IDanmoProvinceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 省份Controller
 *
 * @author yangle
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/province")
public class DanmoProvinceController extends BaseController
{
    @Autowired
    private IDanmoProvinceService danmoProvinceService;

    /**
     * 查询省份列表
     */
//    @RequiresPermissions("system:province:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoProvince danmoProvince)
    {
        List<DanmoProvince> list = danmoProvinceService.selectDanmoProvinceList(danmoProvince);
        return Result.success(list);
    }

    /**
     * 导出省份列表
     */
//    @RequiresPermissions("system:province:export")
    @Log(title = "省份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoProvince danmoProvince)
    {
        List<DanmoProvince> list = danmoProvinceService.selectDanmoProvinceList(danmoProvince);
        ExcelUtil<DanmoProvince> util = new ExcelUtil<DanmoProvince>(DanmoProvince.class);
        util.exportExcel(response, list, "省份数据");
    }

    /**
     * 获取省份详细信息
     */
//    @RequiresPermissions("system:province:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoProvinceService.selectDanmoProvinceById(id));
    }

    /**
     * 新增省份
     */
//    @RequiresPermissions("system:province:add")
    @Log(title = "省份", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoProvince danmoProvince)
    {
        return toAjax(danmoProvinceService.insertDanmoProvince(danmoProvince));
    }

    /**
     * 修改省份
     */
//    @RequiresPermissions("system:province:edit")
    @Log(title = "省份", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoProvince danmoProvince)
    {
        return toAjax(danmoProvinceService.updateDanmoProvince(danmoProvince));
    }

    /**
     * 删除省份
     */
//    @RequiresPermissions("system:province:remove")
    @Log(title = "省份", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoProvinceService.deleteDanmoProvinceByIds(ids));
    }

    /**
     * 查询市
     * @param danmoProvinceReq
     * @return
     */
    @PostMapping("selectProvinceCode")
    public Result selectProvince(@RequestBody DanmoProvinceReq danmoProvinceReq)
    {
       List<DanmoCity> danmoCityList= danmoProvinceService.selectProvinceCode(danmoProvinceReq);
        return success( danmoCityList);
    }

    /**
     * 查询县
     * @param danmoCountyReq
     * @return
     */
    @PostMapping("selectCityCode")
    public Result selectCityCode(@RequestBody DanmoCountyReq danmoCountyReq)
    {
       List<DanmoCounty> danmoCityList= danmoProvinceService.selectCityCode(danmoCountyReq);
        return success( danmoCityList);
    }
}
